package MCQReaderAnsweredAnalyze;

import javax.swing.JOptionPane;
import javax.swing.tree.TreeNode;

import MCQReaderInterface.MainInterface;

public class AnsewredQCMAnalyse {

	private static AnalyzeSelectedZone analyseur;
	private static ImageManager imageManager;

	static {
		setAnalyseur(new AnalyzeSelectedZone(MainInterface.getThisIsIt()
				.getRightFrame().getPdfCalque().myGraphics()));
		setImageManager(new ImageManager());
	}

	public static void startAnalyse(String resultFilePath) {

		Thread thread = new Thread(new Runnable() {
			public void run() {
				String[] choix = { "merci" };
				JOptionPane.showOptionDialog(null, "Analyse terminée !",
						"Analyse en cours ...", JOptionPane.OK_OPTION,
						JOptionPane.INFORMATION_MESSAGE, null, choix, choix[0]);
			}

		});

		if (DialogBeforeAnalyzis.canBeginAnalyzis()) {
			int nbQCM = DialogBeforeAnalyzis.getNbQCM();
			PrintAnalysisResult print = new PrintAnalysisResult(resultFilePath);
			TreeNode node = MainInterface.getThisIsIt().getLeftFrame()
					.getTree().getRacine();

			thread.start();
			for (int i = 0; i < nbQCM; i++) {
				if (i == nbQCM - 1)
					print.setTheEnd(true);
				print.printResult(node, analyseur.getG(), imageManager
						.getCurrentImage());
			}
		}

	}

	/**
	 * @param imageManager
	 *            the imageManager to set
	 */
	public static void setImageManager(ImageManager imManager) {
		imageManager = imManager;
	}

	/**
	 * @return the imageManager
	 */
	public static ImageManager getImageManager() {
		return imageManager;
	}

	/**
	 * @param analyseur
	 *            the analyseur to set
	 */
	public static void setAnalyseur(AnalyzeSelectedZone anal) {
		analyseur = anal;
	}

	/**
	 * @return analyzer
	 */
	public static AnalyzeSelectedZone getAnalyseur() {
		return analyseur;
	}
}
